/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package server;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.xml.sax.InputSource;

/**
 *
 * @author Mateusz
 */
public class Config {

    private List<String> servers = new ArrayList<String>();
    private String SVNAddress;
    private String SVNUsername;
    private String SVNPassword;
    private String adminMail;
    private String testClassPath;
    private String appRoot;
    private int port;
    private static String localMainPath = "~/SVNRepoTest";

    public Config(String configFile) {
        try {
            XPathFactory factory = XPathFactory.newInstance();
            XPath xPath = factory.newXPath();
            String SVNAddressQuery = "/config/SVNData/address/text()";
            String SVNUsernameQuery = "/config/SVNData/username/text()";
            String SVNPasswordQuery = "/config/SVNData/password/text()";
            String adminMailQuery = "/config/adminMail/text()";
            String testClassPathQuery = "/config/testClassPath/text()";
            String appRootQuery = "/config/appRoot/text()";
            String portQuery = "/config/SVNData/port/text()";
            SVNAddress = xPath.evaluate(SVNAddressQuery, new InputSource(new FileReader(configFile)));
            SVNUsername = xPath.evaluate(SVNUsernameQuery, new InputSource(new FileReader(configFile)));
            SVNPassword = xPath.evaluate(SVNPasswordQuery, new InputSource(new FileReader(configFile)));
            adminMail = xPath.evaluate(adminMailQuery, new InputSource(new FileReader(configFile)));
            testClassPath = xPath.evaluate(testClassPathQuery, new InputSource(new FileReader(configFile)));
            appRoot = xPath.evaluate(appRootQuery, new InputSource(new FileReader(configFile)));
            port = Integer.parseInt(xPath.evaluate(portQuery, new InputSource(new FileReader(configFile))));
        } catch (FileNotFoundException ex) {
            System.out.println("1");
        } catch (XPathExpressionException ex) {
            System.out.println("2");
            ex.printStackTrace();
        }
    }

    public String getSVNAddress() {
        return SVNAddress;
    }

    public String getSVNPassword() {
        return SVNPassword;
    }

    public String getSVNUsername() {
        return SVNUsername;
    }

    public String getAdminMail() {
        return adminMail;
    }

    public List<String> getServers() {
        return servers;
    }

    public String getTestClassPath() {
        return testClassPath;
    }

    public String getAppRoot() {
        return appRoot;
    }

    public int getPort() {
        return port;
    }

    public static String getLocalMainPath() {
        return localMainPath;
    }
}
